﻿using DotSpatial.Projections;

namespace GeometryServer.Services
{
    public static class ExtentionMethods
    {
        public static void Project(this GISServer.Core.Client.Geometry.Point point, int insrid, int outsrid)
        {
            var xy = new double[2];
            xy[0] = point.X;
            xy[1] = point.Y;
            var projectedpoint= DotSpatialProjectPoint(xy,insrid, outsrid);
            point.X = projectedpoint.X;
            point.Y = projectedpoint.Y;
        }

        public static void Project(this GISServer.Core.Client.Geometry.GeometryArray geometies, int insrid, int outsrid)
        {
           
        }


        private static GISServer.Core.Client.Geometry.Point DotSpatialProjectPoint(double[] xy, int insrid, int outsrid)
        {
            xy = new double[2];
            xy[0] = -117;
            xy[1] = 34;
            
            double[] z = new double[1];
            z[0] = 1;
            
            ProjectionInfo pStart = ProjectionInfo.FromEpsgCode(insrid);
            
            ProjectionInfo pEnd = ProjectionInfo.FromEpsgCode(outsrid);
            
            Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);
            return new GISServer.Core.Client.Geometry.Point(xy[0], xy[1]);
        }

    }
}